import config from "@/commons/config.js";
export default {
  padZero: (num) => {
    return num < 10 ? "0" + num : num;
  },
  getImgUrl(url) {
    return config.baseUrl + url;
  },
  toast(msg, duration = 1500) {
    uni.showToast({
      title: msg,
      icon: "none",
      duration,
    });
  },
  uploadImg() {
    return new Promise((resolve, reject) => {
      const accessToken = uni.$sc.storage.get("accessToken");
      uni.chooseImage({
        count: 1,
        success: (res) => {
          uni.uploadFile({
            url: config.uploadUrl,
            filePath: res.tempFilePaths[0],
            name: "file",
            header: {
              Token: `Bearer ${accessToken}`,
              Authorization: `Bearer ${accessToken}`,
            },
            formData: {
              user: "test",
            },
            success: (res) => {
              resolve(JSON.parse(res.data));
            },
          });
        },
      });
    });
  },
};
